home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: tank.news.pipex.net!pipex!swrinde!gatech!psinntp!psinntp!psinntp!psinntp!bbnews1!trsvr!news
- From: bmr1@trpo4.tr.unisys.com (Benjamin Romer)
- Subject: Re: C, C++, or both..??
- Sender: news@tr.unisys.com (cnews news id.)
- Message-ID: <DLyBD0.1nM@tr.unisys.com>
- Date: Mon, 29 Jan 1996 16:34:12 GMT
- X-Nntp-Posting-Host: bmr1.tr.unisys.com
- References: <4ehif2$ljf@news.iconn.net>
- Organization: Unisys Corporation
- X-Newsreader: WinVN NT 0.92.6
-
- In article <4ehif2$ljf@news.iconn.net>, thecrow@iconn.net (The Crow) says:
- >
- >I am 17 years old, I have a rudimentary understanding of both C and C++ at this
- >point.(I know Pascal well) I want to really delve into something at this point.
- >My eventual goal is to either start my own software company, or work for one as
- >a programmer. Should I concentrate only on C++ for now, only C for now, or
- >both? Or does it not really matter? I have read up on C++ and I really don't
- >see much benefit from it. People have kept applications in order (mostly) for
- >years without 'object oriented' programming...and C seems to be faster and much
- >less of a pain.
-
- C++ has *a lot* on "good old C", one aspect being that it is Good Old C, but
- with a whole bunch of useful extensions. Although from a rudimentary standpoint,
- it may seem like there's little use for OOP, once you begin to realize some of the
- advantages that it gives, you'll wonder how you got along without them. For instance,
- writing an application for Windows in straight C requires you to do a lot of low and
- mid-level programming, everything from interpreting the message to resize a window
- to sending a keyboard keypress to the right place. In a higher-level language like
- C++, you can write code to do these things _once_, then reuse the code for
- multiple projects. This allows the programmer to concentrate on _solving_the_problem_
- rather than dealing with system architecture. Several premade libraries of code exist
- for just this purpose; I can think of two examples, Borland's OWL system, and the
- Microsoft MFC system, that you could look into for a better idea of what I mean.
-
- Another benefit can be seen when you begin to work in large groups on a project.
- In C, when two people would have to work together, they'd have to agree on a specific
- way to name every function and structure to prevent them from redefining another's
- code. With C++, The programmers can each be handed a design specification by
- the project leader, and they can use each other's objects without having to know
- specifics. For instance, suppose a colleague and I are writing a program, and we
- need to implement both a tree and a linked list. in straight C, we'd have to define
- TreeGetParent() and ListGetParent(), while in C++, we can both use GetParent() and
- let the compiler worry about which one to use. Although this example is trivial,
- I can easily imagine cases in which the same _semantic_ action must be applied
- to many different data structures, making calling the correct function much harder.
-
- This leads me to a third point. There are a few things that you can do with C++ that
- you just cannot match with straight C. Using C++ inheritance, we can define a set
- of things, say, cars, which may all work in different ways, but are all basically the
- same. I can make a Car class in C++, then derive DieselCar and ElectricCar from
- that class. Then, suppose I have a Race() function [for a game, perhaps!] to which
- I get a pointer to a Car:
-
- void Race(Car *move)
- {
- move->Accelerate();
- }
-
- Not only do I not need to know which kind of Car it is, electric or diesel, but I also
- don't need to wonder what is the proper function to call! In straight C, you'd need
- the type of car as well as a switch statement, which could get *UGLY* if there's
- thirty or fourty types of cars.
-
- >I have a few programs in mind were object orientation would be a more natural
- >way of going about the program (evolution similuations) but a lot of programs
- >don't really benefit from it at all. The biggest improvements in C++ that I
- >can see at this point are COUT/CIN, the comments, and NEW and DELETE...the rest
- >just seems to make me type and think more. Is it because I am just not used to
- >the idea yet or is it really more complicated? The thing I hate most is the way
- >member functions have to be outside of their class, totally counter intuitive
- >and makes things very hard to follow.
-
- Actually, you can define the functions inline. Usually it is not done so that the
- interface to the code can be examined without having to read the implementation.
- This is another basis of OOP: the programmer, given an interface to the object,
- shouldn't have to know how it works "on the inside". Suppose you've got a digital
- watch; there are buttons for displaying the date, setting the alarm, etc. Do you
- need to know how the internal circuitry works to press the buttons?
-
- I'd suggest you get a good book on OOP. Try "Developing C++ Software" by
- Russel Winder, published by Wiley Professional Computing. It should fill out
- some of the holes in your experiences with C++, and answer some of the
- questions you have about using C++ effectively. If you'd like to contact me,
- send mail to bmr1@trpo4.tr.unisys.com, or preferrably avenger@trend1.com.
-
- Ben Romer
- Software Engineer
- Unisys Corporation
-
- #include <stddisclaim.txt>
-
-
-
- >The Crow - thecrow@iconn.net
- >"It can't rain all the time"
- >-Kryptology
- >
-